﻿CREATE PROCEDURE [dbo].[proc_Employee_Getlist_WageJx_Count]
	(
		@CompanyId int,
		@DepartmentId int,
		@CurMonth nvarchar(7),
		@Stext nvarchar(50)
	)
AS
begin
		declare @indextable table(id int identity(1,1),nid int)
		;WITH ChildDepartment(ID,DName,PId) AS
		(
			SELECT ID,DName,ParentID FROM department WHERE id=@DepartmentId
			UNION ALL
			SELECT department.ID,department.DName,department.ParentID FROM ChildDepartment AS d
			INNER JOIN department ON d.ID = department.ParentID
		)
		insert into @indextable(nid) select Id from ChildDepartment;
	
	Select
		Count(Id)
	From Employee e
	Where (@CompanyId=0 Or e.CompanyId=@CompanyId) and (@DepartmentId=0 Or e.DepartmentId in (select c.nid from @indextable c))
	and (@Stext is null Or EName like '%'+@Stext+'%')

end
	RETURN
